Validate sample format in ip_open()
authorihy123 <aladinandreyy@gmail.com>
Sun, 17 Aug 2025 11:28:46 +0000 (14:28 +0300)
committerSebastian Ramacher <sramacher@debian.org>
Fri, 12 Sep 2025 21:00:35 +0000 (23:00 +0200)
To prevent segfault in ip_setup() because channels=0, validate ip_data->sf
after opening ip.

Gbp-Pq: Name 0007-Validate-sample-format-in-ip_open.patch

input.c

diff --git a/input.c b/input.c
index c20cb3f6a408299ccabbe095a560b09f3f375880..f5c5b3c24c7460bd33019da2e52a4e5bc42c3fdc 100644 (file)
--- a/input.c
+++ b/input.c
@@ -605,6 +605,16 @@ int ip_open(struct input_plugin *ip)
                ip_reset(ip, 1);
                return rc;
        }
+
+       unsigned bits = sf_get_bits(ip->data.sf);
+       unsigned channels = sf_get_channels(ip->data.sf);
+       unsigned rate = sf_get_rate(ip->data.sf);
+       if (!bits || !channels || !rate) {
+               d_print("corrupt file: bits = %u, channels = %u, rate = %u\n",
+                               bits, channels, rate);
+               return -IP_ERROR_FILE_FORMAT;
+       }
+
        ip->open = 1;
        return 0;
 }